package starter.game.netty.contxt;

import io.netty.channel.ChannelHandlerContext;

import java.util.Map;

import com.bowlong.net.TcpChannel;
import com.bowlong.tool.Lib2;
import com.bowlong.util.MapEx;

@SuppressWarnings({ "rawtypes" })
public abstract class AbstractChannelContext extends Lib2 implements TcpChannel {
	public final ChannelHandlerContext chc;
	public Map params;
	public int cmd;
	public int sid; // session id
	public int uid; // user id
	public String ip;
	protected int inLen;

	public AbstractChannelContext(ChannelHandlerContext chc, int inLen,
			Map params) throws Exception {
		this.chc = chc;
		init(inLen, params);
	}

	public void init(int inLen, Map params) throws Exception {
		this.params = params;
		this.cmd = MapEx.getInt(params, 0);
		this.sid = MapEx.getInt(params, -100);
		this.inLen = inLen;

		if (this.ip == null)
			this.ip = this.chc.channel().remoteAddress().toString();

	}

	public String name() {
		return ""; // 用户名
	}
}
